home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / lib / gcc-lib / djgpp / 2.952 / units / crtdjgpp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-08  |  4.3 KB  |  139 lines

  1. /*
  2. This file implements some system-specific functions, as described in
  3. crtc.c, for DJGPP (using PDCurses).
  4.  
  5. Copyright (C) 1998-2001 Free Software Foundation, Inc.
  6.  
  7. Author: Frank Heckenbach <frank@pascal.gnu.de>
  8.  
  9. This file is part of GNU Pascal.
  10.  
  11. GNU Pascal is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2, or (at your option)
  14. any later version.
  15.  
  16. GNU Pascal is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with GNU Pascal; see the file COPYING. If not, write to the
  23. Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  24. 02111-1307, USA.
  25.  
  26. As a special exception, if you link this file with files compiled
  27. with a GNU compiler to produce an executable, this does not cause
  28. the resulting executable to be covered by the GNU General Public
  29. License. This exception does not however invalidate any other
  30. reasons why the executable file might be covered by the GNU General
  31. Public License.
  32. */
  33.  
  34. #include <pc.h>
  35. #include <go32.h>
  36. #include <dpmi.h>
  37.  
  38. /* We could also use the PDCurses version (by removing the following
  39.    define and function), but this function will distinguish between
  40.    left and right modifiers better. */
  41. #define HAVE_CRT_GETSHIFTSTATE
  42. int crt_getshiftstate ()
  43. {
  44.   int state = crt_VirtualShiftState;
  45.   unsigned short bios_state;
  46.   /* read a word from BIOS memory at linear address 0x417 (i.e., 0x40:0x17) */
  47.   _dosmemgetw (0x417, 1, &bios_state);
  48.   if (bios_state & 2) state |= shLeftShift;
  49.   if (bios_state & 1) state |= shRightShift;
  50.   if (bios_state & 4) state |= (bios_state & 0x100) ? shLeftCtrl : shRightCtrl;
  51.   if (bios_state & 8) state |= (bios_state & 0x200) ? shLeftAlt  : shRightAlt;
  52.   if (bios_state & 0x1000) state |= shExtra;
  53.   return state;
  54. }
  55.  
  56. #define HAVE_CRT_SOUND
  57. void crt_sound (unsigned Hz)
  58. {
  59.   sound (Hz);
  60. }
  61.  
  62. void crt_nosound ()
  63. {
  64.   nosound ();
  65. }
  66.  
  67. static void VideoInterrupt (int a, int b, int c, int d, int *ra, int *rb, int *rc, int *rd)
  68. {
  69.   __dpmi_regs Regs;
  70.   memset (&Regs, 0, sizeof (Regs));
  71.   Regs.x.ax = a;
  72.   Regs.x.bx = b;
  73.   Regs.x.cx = c;
  74.   Regs.x.dx = d;
  75.   __dpmi_int (0x10, &Regs);
  76.   if (ra) *ra = Regs.x.ax;
  77.   if (rb) *rb = Regs.x.bx;
  78.   if (rc) *rc = Regs.x.cx;
  79.   if (rd) *rd = Regs.x.dx;
  80. }
  81.  
  82. typedef struct
  83. {
  84.   int Mode, Rows, Columns, Pos, Shape;
  85. } TScrData;
  86.  
  87. static void GetMode (TScrData *ScrData)
  88. {
  89.   VideoInterrupt (0xf00, 0, 0, 0, &ScrData->Mode, NULL, NULL, NULL);
  90.   VideoInterrupt (0x1130, 0, 0, 0, NULL, NULL, NULL, &ScrData->Rows);
  91.   ScrData->Rows = (ScrData->Rows & 0xff) + 1;
  92.   if (ScrData->Rows <= 1) ScrData->Rows = 25;
  93.   ScrData->Columns = ScrData->Mode / 0x100;
  94.   ScrData->Mode = ScrData->Mode % 0x100;
  95.   VideoInterrupt (0x300, 0, 0, 0, NULL, NULL, &ScrData->Shape, &ScrData->Pos);
  96. }
  97.  
  98. static void SetMode (TScrData *ScrData, TScrData *Other)
  99. {
  100.   if (ScrData->Mode != Other->Mode || ScrData->Rows != Other->Rows || ScrData->Columns != Other->Columns)
  101.     {
  102.       VideoInterrupt (0x1202, 0x30, 0, 0, NULL, NULL, NULL, NULL);
  103.       VideoInterrupt (ScrData->Mode, 0, 0, 0, NULL, NULL, NULL, NULL);
  104.       if (ScrData->Rows > 25)
  105.         {
  106.           int TmpRows;
  107.           VideoInterrupt (0x1112, 0, 0, 0, NULL, NULL, NULL, NULL);
  108.           VideoInterrupt (0x1130, 0, 0, 0, NULL, NULL, NULL, &TmpRows);
  109.           if (TmpRows == 42) VideoInterrupt (0x1200, 0x20, 0, 0, NULL, NULL, NULL, NULL);
  110.         }
  111.     }
  112.   VideoInterrupt (0x200, 0, 0, ScrData->Pos, NULL, NULL, NULL, NULL);
  113.   VideoInterrupt (0x100, 0, ScrData->Shape, 0, NULL, NULL, NULL, NULL);
  114. }
  115.  
  116. #define HAVE_CRT_SAVE_RESTORE_SCREEN
  117. static int crt_save_restore_screen (Boolean Restore)
  118. {
  119.   static int OrigModeSet = 0, ProgModeSet = 0;
  120.   static TScrData Orig, Prog;
  121.   static void *Buf = NULL;
  122.   if (!Restore)
  123.     {
  124.       GetMode (&Orig);
  125.       OrigModeSet = 1;
  126.       if (Buf) free (Buf);
  127.       if ((Buf = malloc (2 * Orig.Columns * Orig.Rows))) ScreenRetrieve (Buf);
  128.       if (ProgModeSet) SetMode (&Prog, &Orig);
  129.     }
  130.   else
  131.     {
  132.       GetMode (&Prog);
  133.       ProgModeSet = 1;
  134.       if (OrigModeSet) SetMode (&Orig, &Prog);
  135.       if (Buf) ScreenUpdate (Buf);
  136.     }
  137.   return Buf != NULL;
  138. }
  139.